package com.yuanchu.store.controller;

import com.yuanchu.common.utils.PageResult;
import com.yuanchu.common.utils.R;
import com.yuanchu.common.validator.ValidationGroups;
import com.yuanchu.store.dto.EditHelpParamsDto;
import com.yuanchu.store.dto.QueryPageParams;
import com.yuanchu.store.entity.YoshopHelpEntity;
import com.yuanchu.store.service.YoshopHelpService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @version: 1.0
 * @Author: adan
 * @description: HelpController
 * @date: 2024-01-26 18:07
 */
@RestController
@RequestMapping("help")
public class ShopHelpController {

    @Resource
    public YoshopHelpService helpService;

    @GetMapping("/list")
    public R queryHelpList(@RequestParam(required = false) QueryPageParams params) {
        PageResult<YoshopHelpEntity> list = helpService.queryHelpList(params);
        Map<String, Object> map = new HashMap<>();
        map.put("list", list);
        return R.ok().put("data", map);
    }

    @PostMapping("/add")
    public R addHelp(@RequestBody @Validated({ValidationGroups.Insert.class}) YoshopHelpEntity form) {
        helpService.addHelp(form);
        return R.ok();
    }

    @PostMapping("/edit")
    public R editHelp(@RequestBody @Validated({ValidationGroups.Update.class}) EditHelpParamsDto params) {
        helpService.editHelp(params);
        return R.ok();
    }

    @PostMapping("/delete")
    public R deleteHelp(@RequestBody @Validated({ValidationGroups.Delete.class}) EditHelpParamsDto params) {
        helpService.deleteHelp(params);
        return R.ok();
    }
}
